#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include <cstdio>
#include<cstdlib>
using namespace std;

typedef int elemtype;
typedef int status;

#define null 0 
typedef struct lnode
{
    elemtype data;
    struct lnode* next;
}lnode, * linklist;



void createlist(linklist& l)
{
    linklist rear, p;
    l = rear = new lnode;
    /*l=(linklist)malloc(sizeof(lnode));
    l->data=NUll;*/
    l->next = null;
    p = new lnode;
    while (scanf("%d", &(p->data)) != EOF)
    {
        /*cin>>p->data;*/
        rear->next = p;
        rear = p;
        p =/*(lnode*)malloc(sizeof(lnode));*/new lnode;
    }
    rear->next = NULL;
}

status length(linklist l)
{
    linklist p;
    int i = 0;
    p = l->next;
    while (p->next != 0)
    {
        p = p->next;
        i++;
    }
    return i;

}

void print(linklist l)
{
    linklist p;
    p = l->next;
    while (p->next)
    {

        cout << p->data << " ";
        p = p->next;

    }
    cout << p->data << endl;
}


int main()
{
    linklist head1, head2, m, p, l, n;
    int i, j;
    createlist(head1);
    createlist(head2);
    p = head1->next;
    l = head2->next;
    m = n = head1;
    if (head1 == 0)
    {
        print(head2);
        return 0;
    }
    else if (head2 == 0)
    {
        print(head1);
        return 0;
    }
    else
    {
        while (p || l)
        {
            if (p->data < l->data)
            {
                n->next = p;
                n = p;
                p = p->next;

            }
            else
            {
                n->next = l;
                n = l;
                l = l->next;
            }
        }
        n->next = p ? p : l;
        free(l);
        print(m);

    }
}